package com.chen.nio;

import java.nio.IntBuffer;

public class BasicBuffer {
    public static void main(String[] args) {
        //创建一个buffer 大小为5，可以存放五个int
        IntBuffer intBuffer = IntBuffer.allocate(5);
        intBuffer.put(1);
        intBuffer.put(3);
        intBuffer.put(4);
        intBuffer.put(6);
        //intBuffer.put(10);
        //从buffer里面读取数据
        //buffer切换.读写切换
        intBuffer.flip();//翻转
        intBuffer.put(9);
        intBuffer.position(2);
        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }
    }
}
